//
//  FGMyCenterFooterView.swift
//  FlagApp
//
//  Created by momo on 2020/12/31.
//

import UIKit

class FGMyCenterFooterView: UIView,UICollectionViewDelegate,UICollectionViewDataSource {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(titleLab)
        addSubview(collectionView)
        configView()
    }
    
    func configView() {
        titleLab.snp_updateConstraints { (make) in
            make.left.top.equalTo(10)
            make.width.lessThanOrEqualTo(200)
        }
        
        collectionView.snp_updateConstraints { (make) in
            make.top.equalTo(titleLab.snp_bottom).offset(10)
            make.width.equalTo(width)
            make.height.equalTo(height - titleLab.bottom)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var titleLab: UILabel = {
        () -> UILabel in
        let lab = UILabel()
        lab.font = UIFont.systemFont(ofSize: 16)
        lab.text = "常用服务"
        return lab
    }()
    
    lazy var collectionView: UICollectionView = {
        () -> UICollectionView in
        let layout = UICollectionViewFlowLayout()
        layout.itemSize = CGSize(width: (width - 50)/4, height: 80)
        layout.minimumLineSpacing = 10
        layout.minimumInteritemSpacing = 10
        layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
        
        let collection = UICollectionView.init(frame: .zero, collectionViewLayout: layout)
        collection.delegate = self
        collection.dataSource = self
        collection.register(FGServiceCollectionCell.self, forCellWithReuseIdentifier: "serviceCell")
        collection.backgroundColor = UIColor.white
        return collection
    }()
    
    lazy var dataArray: Array = {
        () -> Array<Any> in
        let data = FGMyCenterModel().myCenterServiceData()
        return data
    }()
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "serviceCell", for: indexPath) as? FGServiceCollectionCell
        cell?.backgroundColor = UIColor.white
        cell?.cellModel = self.dataArray[indexPath.row] as? FGMyCenterModel
        return cell!
    }
    
}
